package View;

import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import Controller.ABMBaseController;
import Enums.ABMButtonActions;;

public abstract class ABMBaseView extends BaseView
{
	private static final long serialVersionUID = 1L;
	
	private ABMBaseController controller;
	private JButton btnGuardar;
	private JButton btnCancelar;
	private JButton btnEliminar;
	private JScrollPane panelDatos;
	private JPanel panelEdicion;
	
	public void setPaneles(JScrollPane panelDatos, JPanel panelEdicion)
	{
		this.panelDatos = panelDatos;
		this.panelEdicion = panelEdicion;
	}
	
	public void setBotones(JButton btnGuardar, JButton btnCancelar, JButton btnEliminar)
	{
		this.btnGuardar = btnGuardar;
		this.btnCancelar = btnCancelar;
		this.btnEliminar = btnEliminar;
	}
	
	public void showGrillaDatos(boolean show)
	{
		if(panelDatos != null)
			panelDatos.setVisible(show);
	}
	
	public void showPanelDeEdicion(boolean show)
	{
		if(panelEdicion != null)
			panelEdicion.setVisible(show);
	}
	
	public void showBotonGuardar(boolean show)
	{
		if(btnGuardar != null)
			btnGuardar.setVisible(show);
	}
	
	public void showBotonCancelar(boolean show)
	{
		if(btnCancelar != null)
			btnCancelar.setVisible(show);
	}
	
	public void showBotonEliminar(boolean show)
	{
		if(btnEliminar != null)
			btnEliminar.setVisible(show);
	}
	
	public void actionPerformed(ActionEvent e) 
	{
		ABMButtonActions action = ABMButtonActions.valueOf(e.getActionCommand());
		
		switch (action) 
		{
		case Guardar:
			controller.Guardar();
			break;
		case Cancelar:
			controller.Cancelar();
			break;
		case Eliminar:
			controller.Eliminar();
			break;

		default:
			break;
		}
	}
	
	public ABMBaseController getController()
	{
		return this.controller;
	}
	
	public void setGrillaDatos(JTable tablaEntidades)
	{
		panelDatos.setViewportView(tablaEntidades);
	}
	
	public void setController(ABMBaseController controller)
	{
		this.controller = controller;
		controller.init();
	}
}
